package org.alino.core.shiro.scheduler;

import org.alino.core.utils.LoggerUtils;
import org.apache.shiro.session.mgt.ValidatingSessionManager;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

/**
 * @Desc TODO
 * @Author by Brant
 * @Date 2017/1/13
 */
public class QuartzSessionValidationJob implements Job {
    /**
     * Key used to store the session manager in the job data map for this job.
     */
    public static final String SESSION_MANAGER_KEY = "sessionManager";

    /**
     * Called when the job is executed by quartz. This method delegates to the <tt>validateSessions()</tt> method on the
     * associated session manager.
     *
     * @param context
     *            the Quartz job execution context for this execution.
     */
    public void execute(JobExecutionContext context) throws JobExecutionException {
        JobDataMap jobDataMap = context.getMergedJobDataMap();
        ValidatingSessionManager sessionManager = (ValidatingSessionManager) jobDataMap.get(SESSION_MANAGER_KEY);
        LoggerUtils.debug(getClass(),"Executing session validation Quartz job...");

        sessionManager.validateSessions();

        LoggerUtils.debug(getClass(),"Session validation Quartz job complete.");
    }
}
